<!--  -->
<script setup>
import { ref, reactive, toRefs, defineProps, defineEmits, onBeforeMount, onMounted, watchEffect, computed } from 'vue' // eslint-disable-line
import { useStore } from 'vuex'
import { useRoute, useRouter } from 'vue-router'
import { generateNewStyle, writeNewStyle } from '@/utils/theme'
/**
* 仓库
*/
const store = useStore() // eslint-disable-line
/**
* 路由对象
*/
const route = useRoute() // eslint-disable-line
/**
* 路由实例
*/
const router = useRouter() // eslint-disable-line
// 1-开始创建组件-setup
/**
* Props
*/
defineProps({
  modelValue: {
    type: Boolean,
    required: true
  }
})
const emits = defineEmits(['update:modelValue'])
/**
* 数据部分
*/
// 预定义色值
const predefineColors = [
  '#ff4500',
  '#ff8c00',
  '#ffd700',
  '#90ee90',
  '#00ced1',
  '#1e90ff',
  '#c71585',
  'rgba(255, 69, 0, 0.68)',
  'rgb(255, 120, 0)',
  'hsv(51, 100, 98)',
  'hsva(120, 40, 94, 0.5)',
  'hsl(181, 100%, 37%)',
  'hsla(209, 100%, 56%, 0.73)',
  '#c7158577'
]
// 默认色值
const mColor = ref(store.getters.mainColor)
// 关闭
const closed = () => {
  emits('update:modelValue', false)
}
// 确定
const confirm = async () => {
  // 1.1 获取主题色
  const newStyleText = await generateNewStyle(mColor.value)
  // 1.2 写入最新主题色
  writeNewStyle(newStyleText)
  // 确定时改变颜色
  store.commit('theme/setMainColor', mColor.value)
  // 3. 关闭 dialog
  closed()
}
const data = reactive({}) // eslint-disable-line
// 2.组件挂载页面之前执行----onBeforeMount
onBeforeMount(() => { })
// 3.-组件挂载到页面之后执行-------onMounted
onMounted(() => { })
watchEffect(() => { })
// 使用toRefs解构
// let { } = { ...toRefs(data) } // eslint-disable-line

</script>
<template>
  <el-dialog title="提示" :model-value="modelValue" @close="closed" width="22%">
    <div class="center">
      <p class="title">{{ $t('msg.theme.themeColorChange') }}</p>
      <el-color-picker v-model="mColor" :predefine="predefineColors"></el-color-picker>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="closed">{{ $t('msg.universal.cancel') }}</el-button>
        <el-button type="primary" @click="confirm">{{
        $t('msg.universal.confirm')
        }}</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<style scoped lang='less'>

</style>
